package com.zou.study.zmy;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.util.Iterator;
import java.util.Set;

/**
 * <br/>Date 2021/9/23
 * <br/>Time 11:45:58
 *
 * @author _blank
 */
public class PhotoFileTest {

    public static void main(String[] args) throws IOException {
        final ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();

        serverSocketChannel.socket().bind(new InetSocketAddress(8092));
        serverSocketChannel.bind(new InetSocketAddress(8091));

        serverSocketChannel.configureBlocking(false);

        final Selector selector = Selector.open();
        serverSocketChannel.register(selector, SelectionKey.OP_ACCEPT);


        final Set<SelectionKey> selectionKeys = selector.selectedKeys();
        final Iterator<SelectionKey> iterator = selectionKeys.iterator();
        while (iterator.hasNext()) {
            final SelectionKey selectionKey = iterator.next();
            try {
                if (selectionKey.isAcceptable()) {
                } else if (selectionKey.isConnectable()) {
                } else if (selectionKey.isReadable()) {
                } else if (selectionKey.isWritable()) {
                }
            } finally {
                iterator.remove();
            }
        }
    }

}
